<%--
  Created by IntelliJ IDEA.
  User: Jam
  Date: 2018/2/1
  Time: 22:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>list</title>
</head>
<body>
<form name="itemsForm">
    <input type="button" onclick="add()" value="添加节点"/>
    <input type="text" name="search"/>
    <input type="button" onclick="searchClick('search')" value="搜索"/>
    <table>
        <tr>
            <th><input type="checkbox" onclick="checkAll(this, 'id')"/></th>
            <th>用户名</th>
            <th>姓名</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        <c:forEach items="${pageModel.items}" var="item">
            <tr>
                <td><input type="checkbox" value="${item.id}" name="id"/></td>
                <td>${item.username}</td>
                <td>${item.realName}</td>
                <td>${item.status == true ? "启用" : "禁用"}</td>
                <td>
                    <input type="button" onclick="edit(${item.id})" value="编辑"/>
                    <input type="button" onclick="remove(${item.id})" value="删除"/>
                </td>
            </tr>
        </c:forEach>
    </table>
    <div>
        <input type="button" onclick="prevPage()" value="上一页"/>
        <input type="button" onclick="nextPage()" value="下一页"/>
        <span>第${pageModel.page}页, 总共${pageModel.pageCount}页</span>
        <p>
            <input type="button" onclick="enable()" value="启用">
            <input type="button" onclick="disable()" value="禁用">
            <input type="button" onclick="removes()" value="删除">
        </p>
    </div>
</form>
<script>
    function prevPage() {
        window.location.href = "${pageContext.request.contextPath }/home/user/list?page=${pageModel.prev}&search=${search}";
    }

    function nextPage() {
        window.location.href = "${pageContext.request.contextPath }/home/user/list?page=${pageModel.next}&search=${search}";
    }

    function remove(e) {
        window.location.href = "${pageContext.request.contextPath }/home/user/doDelete?id=".concat(e);
    }

    function removes() {
        document.itemsForm.action = "${pageContext.request.contextPath }/home/user/doDelete";
        document.itemsForm.submit();
    }

    function add() {
        window.location.href = "${pageContext.request.contextPath }/home/user/add";
    }

    function edit(e) {
        window.location.href = "${pageContext.request.contextPath }/home/user/edit?id=".concat(e);
    }

    function enable() {
        document.itemsForm.action = "${pageContext.request.contextPath }/home/user/doEnable";
        document.itemsForm.submit();
    }

    function disable() {
        document.itemsForm.action = "${pageContext.request.contextPath }/home/user/doDisable";
        document.itemsForm.submit();
    }

    function checkAll(e, id) {
        var all = document.getElementsByName(id);
        for (var i = 0; i < all.length; i++) {
            all[i].checked = e.checked;
        }
    }

    function searchClick(e) {
        // document.itemsForm.submit();
        var search = document.getElementsByName(e);
        var searchValue;
        for (var i = 0; i < search.length; i++) {
            searchValue = search[i];
        }
        window.location.href = "${pageContext.request.contextPath }/home/user/list?search=".concat(searchValue.value);
    }

</script>
</body>
</html>
